from typing import List

# 减少不必要的字符串比较
class Solution:
    def maxProduct(self, words: List[str]) -> int:
        words.sort(key = lambda it:len(it), reverse=True)
        wlen = len(words)
        r = 0
        for i in range(wlen - 1):
            wi= words[i]
            for j in range(i + 1, wlen):
                wj = words[j]
                p = len(wi) * len(wj)
                if p > r and not self.__hasComon(wi, wj):
                    r = p
        return r

    def __hasCommon(self, s1, s2):
        a = [0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0]
        for c in s1:
            a[ord(c) - 97] = 1
        for c in s2:
            if a[ord(c) - 97] > 0:
                return True
        return False


solu = Solution()
result = solu.maxProduct(["abcw", "baz", "foo", "bar", "xtfn", "abcdef"])
print(result)
